package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.RoleProvider;
import com.jinmdz.fmis.dao.admin.model.role.RoleEditItem;
import com.jinmdz.fmis.dao.admin.model.role.RoleListData;
import com.jinmdz.fmis.dao.admin.model.role.RoleListItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 业务角色维护Dao
 *
 * @author LiCongLu
 * @date 2020-03-18 11:35
 */
public interface RoleDao {

    /**
     * 查询业务角色列表
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-03-18 11:35
     */
    @SelectProvider(type = RoleProvider.class, method = "loadRoleListWithBusinessSystemId")
    ArrayList<RoleListItem> loadRoleListWithBusinessSystemId(@Param("data") RoleListData data);

    /**
     * 按照主键获取业务角色信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 11:52
     */
    @SelectProvider(type = RoleProvider.class, method = "getRoleEditById")
    RoleEditItem getRoleEditById(@Param("id") Integer id);

    /**
     * 按照角色编码查询非当前角色信息主键
     *
     * @param roleId           当前角色主键
     * @param businessSystemId 系统主键
     * @param roleCode         员工编号
     * @return
     * @author LiCongLu
     * @date 2020-03-18 11:35
     */
    @Select(" select id from business_system_role where id != IFNULL(#{roleId},0) and business_system_id = #{businessSystemId} and role_code = #{roleCode} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getRoleIdByRoleCode(@Param("roleId") Integer roleId, @Param("businessSystemId") Integer businessSystemId, @Param("roleCode") String roleCode);

    /**
     * 按照角色名称查询非当前角色信息主键
     *
     * @param roleId           当前角色主键
     * @param businessSystemId 系统主键
     * @param roleName         角色名称
     * @return
     * @author LiCongLu
     * @date 2020-03-18 11:35
     */
    @Select(" select id from business_system_role where id != IFNULL(#{roleId},0) and business_system_id = #{businessSystemId} and role_name = #{roleName} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getRoleIdByRoleName(@Param("roleId") Integer roleId, @Param("businessSystemId") Integer businessSystemId, @Param("roleName") String roleName);
}
